ta = {};

ta.check = function(data){
	
	if(data['data[TicketAdvisory][question]'] == ''){
		alert('请输入问题');
		return false;
	}
	
	if(data['data[TicketAdvisory][authcode]'] == ''){
		alert('请输入验证码');
		return false;
	}
	
	return true;
};

ta.submit = function(){
	var callback = function(res){
		if(res.state){
			alert(res.msg);
			jQuery('#TicketAdvisoryQuestion').val('');
			$("#auth_code").attr("src",$("#auth_code").attr("base_src")+"?_="+Math.random());
		}else{
			alert(res.msg);
		}
	};
	var data = jQuery('#TicketAdvisoryViewForm').serializeObject();
	if(ta.check(data)){
		ta.action(data,callback);
	}
};

ta.action = function(data,callback){
	$.ajax({
	  type: "post",
	  url: 'TicketAdvisories/add',
	  dataType:'json',
	  data:data,
	}).done(function( msg ) {
		callback(msg);
	});
};
